﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace WebApplication_HighChartDemo
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class BonderDataService
    {
        // 要使用 HTTP GET，请添加 [WebGet] 特性。(默认 ResponseFormat 为 WebMessageFormat.Json)
        // 要创建返回 XML 的操作，
        //     请添加 [WebGet(ResponseFormat=WebMessageFormat.Xml)]，
        //     并在操作正文中包括以下行:
        //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        public List<TestData> getData(int dataCount)
        {
            List<TestData> newDataList = new List<TestData>();

            long jsBeginTick = DateTime.Parse("1970-1-1").Ticks;
            long nowTicks = DateTime.Now.ToUniversalTime().Ticks;
            long nowJsTicks = (nowTicks - jsBeginTick) / (1000 * 10);


            Random r = new Random();

            for (var i = 0; i < dataCount; i++)
            {

                newDataList.Add(new TestData()
                {
                    x = nowJsTicks + i,
                    y = r.NextDouble()
                });

            }
            return newDataList;
        }

        // 在此处添加更多操作并使用 [OperationContract] 标记它们
    }
    public class TestData
    {
        public double x;
        public double y;

    }
}
